﻿package ahxu.crawler;

import java.net.URI;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ahxu.crawler.utils.MD5Utils;

public class CrawlerResult {
	Log logger=LogFactory.getLog(CrawlerResult.class);
	private String id;
	private URI uri;
	private String anthorText;
	
	private Date startTime;
	private Date endTime;

	private byte[] source;
	private String sourceContentEncoding;
	private String sourceContentType;
	private String sourceContentCharset;

	public CrawlerResult(){
		
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public URI getUri() {
		return uri;
	}
	public void setUri(URI uri) {
		this.uri = uri;
	}
	public String getAnthorText() {
		return anthorText;
	}
	public void setAnthorText(String anthorText) {
		this.anthorText = anthorText;
	}

	public byte[] getSource() {
		return source;
	}
	public String getStringSource(String charset){
		try {
			return new String(this.source,charset);
		} catch (Exception e) {
			logger.warn("source content charset is null,using default charset!");
			return new String(this.source);
		}
	}
	public String getStringSource(){
		try {
			return new String(this.source,this.sourceContentCharset);
		} catch (Exception e) {
			logger.warn("source content charset is null,using default charset!");
			return new String(this.source);
		}
		
	}
	public void setSource(byte[] source) {
		this.source = source;
	}
	
	public String getSourceContentType() {
		return sourceContentType;
	}
	public void setSourceContentType(String sourceContentType) {
		this.sourceContentType = sourceContentType;
	}
	public String getSourceContentEncoding() {
		return sourceContentEncoding;
	}
	public void setSourceContentEncoding(String sourceContentEncoding) {
		this.sourceContentEncoding = sourceContentEncoding;
	}
	public String getSourceCountCharset() {
		return sourceContentCharset;
	}
	public void setSourceCountCharset(String sourceCountCharset) {
		this.sourceContentCharset = sourceCountCharset;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public String getSourceContentCharset() {
		return sourceContentCharset;
	}
	public void setSourceContentCharset(String sourceContentCharset) {
		this.sourceContentCharset = sourceContentCharset;
	}
	public String getSourceMd5() {
		return MD5Utils.encode(source);
	}
}
